package com.xej.seat.controller.admin;

import com.xej.seat.service.SeatService;
import com.xej.seat.service.UserService;
import com.xej.seat.util.ResultInfo;
import com.xej.seat.util.ResultInfoFactory;
import com.xej.seat.vo.*;

import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 后台管理 座位controller
 */
@Controller
@RequestMapping("/admin/seat")
public class AdminSeatController {
    private Logger log = LoggerFactory.getLogger(AdminSeatController.class);
    
    @Resource
    private SeatService seatService;

    @Resource
    private UserService userService;
    
    /**
     * 初始化分页信息 获取totalcount
     * @param pager 分页对象
     * @return
     */
    @RequestMapping("/initPage")
    @ResponseBody
    public Pager initPage(Pager pager){
    	seatService.initPage(pager);
        return pager;
    }
    
    @RequestMapping("/initSeat")
    @ResponseBody
    public ResultInfo initSeat(Seat seat, HttpServletRequest request){
    	seatService.initSeat(seat);
        return ResultInfoFactory.getSuccessResultInfo("创建座位成功！！！");
    }
    
    /**
     * 跳转到添加页面
     * @return
     */
    @RequestMapping("/addSeat")
    public String addPage() {
        return "admin/seat/seatAdd";
    }
    
    /**
     *跳转编辑页面
     */
    @RequestMapping("/editSeat")
    public String editPage(@Param("sid") String sid,Model model) {
    	//查询详细
    	HashMap<String, Object> params = new HashMap<>();
    	params.put("sid", sid);
    	model.addAttribute("seat", seatService.querySeatByParams(params).get(0));   
        return "admin/seat/seatEdit";
    }
    
    @RequestMapping("/updateSeat")
    @ResponseBody
    public Integer updateSeat( Seat seat ) {
    	HashMap<String, Object> params = new HashMap<>();
    	params.put("sid", seat.getSid());
    	params.put("seatingType",seat.getSeatingType());
//    	seatService.editSeat(params);
		return 1;
    	
    }
    
    /**
     * 加载座位信息列表
     * @param pager 分页对象
     * @param categoryName  搜索条件
     * @param model
     * @return
     */
    @RequestMapping("/load")
    public String loadSeat(Pager pager ,String cusName,Model model){
        List<Seat> seatList = seatService.loadSeat(pager,cusName);
        model.addAttribute("seatList",seatList);
        return "admin/seat/seatTable";
    }
}